
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region NoteFilter Model -(by fangyifeng at 2007-09-14 12:24:13)

	/// <summary>
	/// NoteFilter object'NoteFilter'.
	/// </summary>
	[Serializable]
	public class NoteFilter : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected string _cell;
		protected DateTime _filteDate;
		protected string _reason;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public NoteFilter() { }

		public NoteFilter( string cell, DateTime filteDate, string reason )
		{
			this._cell = cell;
			this._filteDate = filteDate;
			this._reason = reason;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual string Cell
		{
			get { return _cell; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for Cell", value, value.ToString());
				_cell = value;
			}
		}

		public virtual DateTime FilteDate
		{
			get { return _filteDate; }
			set { _filteDate = value; }
		}

		public virtual string Reason
		{
			get { return _reason; }
			set
			{
				if ( value != null && value.Length > 100)
					throw new ArgumentOutOfRangeException("Invalid value for Reason", value, value.ToString());
				_reason = value;
			}
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is NoteFilter))
				throw new InvalidCastException("This object is not of type NoteFilter");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((NoteFilter)obj).Id);
					break;
				case "Cell":
					relativeValue = this.Cell.CompareTo(((NoteFilter)obj).Cell);
					break;
				case "FilteDate":
					relativeValue = this.FilteDate.CompareTo(((NoteFilter)obj).FilteDate);
					break;
				case "Reason":
					relativeValue = (this.Reason != null) ? this.Reason.CompareTo(((NoteFilter)obj).Reason) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (NoteFilter.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
